# -*- mode: sh -*-

# If not running interactively, do nothing.
[ -z "$PS1" ] && return

################################################################
### History

# Do not put duplicate lines in the history.
HISTCONTROL=erasedups:ignorespace
HISTSIZE=1000
HISTTIMEFORMAT='%Y-%m-%d %H:%M  '
HISTIGNORE="cd:pwd:ls:l:ll:fg:bg:jobs:j"
HISTFILESIZE=9999

# Double check of history substitutions.
shopt -s histverify
# All terminals use .bash_history file without overwriting it.
shopt -s histappend
#PROMPT_COMMAND="history -a"

################################################################
### Command prompts and titles

PS1='\[\033[32m\]\A \[\033[0m\]\u\[\033[35m\]@\[\033[0m\]\h \[\033[40;1;33m\]\j\[\033[0;0;36m\] \! \[\033[1;34m\]\w\[\033[1;37m\]\n\[\033[0;1;31m\]\$\[\033[0m\] '
PS2='\[\e[34m\]\#>\[\e[0m\] '

if [ -n "$GUIX_ENVIRONMENT" ]; then
    PS1="\[\033[31m\][guix env] $PS1"
fi

case "$TERM" in
    xterm*|rxvt*)
        PS1="\[\e]0;\W\a\]$PS1"
        ;;
    *)
        ;;
esac

################################################################
### Aliases

alias ls='ls --color=auto'
alias dir='dir --color=auto'
alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'

alias sudo='sudo '
alias se='SUDO_EDITOR=emacsclient sudoedit'

alias ll='ls -AlFh --group-directories-first'
alias l='ls -CAF --group-directories-first'
alias j='jobs'
alias p='pgrep -l'
alias temperature='sudo hddtemp /dev/sd[ab]'
alias pingg='ping -c3 google.com'

alias pac='pacman'
alias pacq='pacman -Q'
alias pacqi='pacman -Qi'
alias pacql='pacman -Ql'
alias pacqo='pacman -Qo'
alias pacqs='pacman -Qs'
alias pacs='sudo pacman -S'
alias pacsuy='sudo pacman -Suy'
alias pacss='pacman -Ss'
alias pacsi='pacman -Si'
alias pacr='sudo pacman -R'
alias pacu='sudo pacman -U'

alias reboot='sudo reboot'
alias halt='sudo halt'
alias hyp-suspend='ssh root@hyperion "systemctl start systemd-suspend"'

alias sc='sudo systemctl --no-pager'
alias scu='systemctl --user --no-pager'
alias scd='sudo systemctl daemon-reload'
alias scud='systemctl --user daemon-reload'
alias scuenv='systemctl --user --no-pager --full show-environment'
alias scenv='systemctl --no-pager --full show-environment'

alias Herd='sudo /run/current-system/profile/bin/herd'
alias doc='herd doc'
alias status='herd status'
alias stop='herd stop'
alias start='herd start'
alias restart='herd restart'
alias Doc='Herd doc'
alias Status='Herd status'
alias Stop='Herd stop'
alias Start='Herd start'
alias Restart='Herd restart'

alias e='emacs --no-site-file &'
alias eq='emacs -nw -Q'
alias gc='guile-compile'
alias m='mpv --quiet'
alias my='mpv --quiet --ytdl'
alias y='youtube-dl'
alias yg='youtube-dl -f22'
alias yb='youtube-dl -f18'

################################################################
### Misc

shopt -s autocd
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# Unbind C-s and C-u.
# stty -ixon
stty kill ^- stop ^-

# Disable 'suspend' builtin command as I use a script with the same name.
enable -n suspend
